﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Domain;


namespace BelDecor.Net.Pages
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        public void btnLogin_Click(object sender, EventArgs args)
        {

            var func = VerificaUsuario(txtUsuario.Text.Trim(), txtSenha.Text.Trim());

            try
            {
                if (func == null)
                {
                    RadWindowManager1.RadAlert("Usuário e Senha inválidos", 0, 0, "", "");
                }
                else
                {
                    Session["userId"] = func.id;
                    Response.Redirect("~/Pages/Inicio.aspx");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        Domain.Model.Funcionario VerificaUsuario(string login, string password)
        {
            try
            {
                var func = Domain.Model.Funcionario.SingleOrDefault(f => f.login == txtUsuario.Text.ToUpper() && f.Senha == txtSenha.Text);
                return func;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

    }
}